package bstsetcode;

/**
 * @author noob
 * @version 1.0
 * @date 2021/3/13 21:52
 */
public class InsertionSortT {

    public static <E extends Comparable<E>> void sort(E[] data){

        for (int i = 0; i < data.length; i++) {
            for (int j = i; j-1>=0; j--) {  //j-1>0
                if(data[j].compareTo(data[j-1]) < 0 ){
                    exchange(data,j,j-1);
                }else {
                    break;
                }
            }
        }
    }

    private static <E extends Comparable<E>> void exchange(E[] data, int i, int j) {
        //交换
        E temp = data[i];
        data[i] = data[j];
        data[j] = temp;
    }
}
